package com.uinnova.product.eam.init.cassso;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.essence.iam.cas.client.SingleLogoutListener;
import com.uinnova.project.base.diagram.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import static com.uinnova.product.eam.init.cassso.CASConfig.GUOTOU_USER_KEY_PREFIX;

/**
 * @description: 国投IAM登录监听器
 * @author: LiMG
 * @create: 2024-05-29 17:07:25
 **/
@Slf4j
public class CASLogoutListener extends SingleLogoutListener {

    @Autowired
    private RedisUtil redisUtil;

    public CASLogoutListener(JSONObject config) {
        super(config.getString("eaServerUrl"), config.getString("casServerUrl"));
    }

    @Override
    protected void onUserLogout(String ticket) {
        // 删除redis缓存中的用户信息
        try {
            redisUtil.del(GUOTOU_USER_KEY_PREFIX + ticket);
        } catch (Exception e) {
            log.error("redis删除登录会话异常{}", JSON.toJSONString(e));
        }
    }

}
